const express = require('express');
const {addBlogService, getBlogListService, getBlogByIdService, updateBlogService, deleteBlogService} = require("../service/blogService");
const router = express.Router();

// 添加文章
router.post('/', async function (req, res, next) {
    // console.log(req.body)
    res.send(await addBlogService(req.body))
})
// 分页获取文章
router.get('/', async function (req, res, next) {
    // console.log(req.query)
    res.send(await getBlogListService(req.query))
})
// 获取某篇文章
router.get('/:id', async function (req, res, next) {
    res.send(await getBlogByIdService(req.params.id, req.headers.authorization))
})
// 修改某篇文章
router.put('/:id', async function (req, res, next) {
    res.send(await updateBlogService(req.params.id, req.body))
})
// 删除某篇文章
router.delete('/:id', async function (req, res, next) {
    res.send(await deleteBlogService(req.params.id))
})

module.exports = router;
